#include <Def.h>
#include <osgEarth/GeoData>
#include "SDKCorePrivate.h"
#include "HelperPrivate.h"

HelperPrivate::HelperPrivate(QObject* parent) :
QObject(parent)
{
}

HelperPrivate::~HelperPrivate()
{
}

bool HelperPrivate::getLonAndLatUnderByScreenPosition(int x,int y,double& lon,double& lat)
{
	osg::Vec3d world;
	osgUtil::LineSegmentIntersector::Intersections hits;
	if(GLOBAL_OSG_VIEW && GLOBAL_OSG_VIEW->computeIntersections(x,y,hits))
	{
		world = hits.begin()->getWorldIntersectPoint();
		osgEarth::GeoPoint mapPoint;
		auto srs = GLOBAL_OSG_MAP_NODE->getTerrain()->getSRS();
		bool ok = mapPoint.fromWorld(srs,world);
		if(!ok)
			return false;

		lon = mapPoint.x();
		lat = mapPoint.y();
		return true;
	}
	return false;
}